//
//  MateTypeViewController.m
//  TQY
//
//  Created by 甘世清 on 2024/9/30.
//

#import "MateTypeViewController.h"
 
#import "MateTypeCollectionViewCell.h"
#import "MateTypeModel.h"
@interface MateTypeViewController ()<UICollectionViewDataSource,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@end

@implementation MateTypeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.zx_navTitle = SQNSLocalString(@"活动类型");
}
- (void)SQ_UIViewForSelfView{
    
    [self.collectionView registerClass:[MateTypeCollectionViewCell class] forCellWithReuseIdentifier:@"MateTypeCollectionViewCell"];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.view addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.view);
            make.top.equalTo(self.zx_navBar.mas_bottom);
    }];
    [self SQ_Header];
}

- (void)SQ_Header{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:@"lug_type" forKey:@"key"];
    [HttpTool post:@"config/details" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        NSDictionary * data = [[NSDictionary alloc]initWithDictionary:httpModel.data];
        NSString * value = [NSString stringWithFormat:@"%@",[data objectForKey:@"value"]];
        NSArray * array = [value mj_JSONObject];
        [self.jsonArray removeAllObjects];
        for (NSString * string in array) {
            MateTypeModel * model = [MateTypeModel new];
            model.string = string;
            if ([string isEqualToString:self.typeString]) {
                model.isSeleted = YES;
            }  
            [self.jsonArray addObject:model];
        }
        [self.collectionView reloadData];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.jsonArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath{
    MateTypeCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MateTypeCollectionViewCell" forIndexPath:indexPath];
    cell.model = [self.jsonArray objectAtIndex:indexPath.item];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake((SCREEN_WIDETH-28)/3.f, 40);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 4;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 4;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(10, 10, 0, 10);
}
 
 //点击事件
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    MateTypeModel * model = [self.jsonArray objectAtIndex:indexPath.item];
    if (self.typeStringBlock) {
        self.typeStringBlock(model.string);
    }
    [self SQ_popViewVC];
}


@end
